<template>
  <div class="contaiter">
    <el-form
      ref="specialtyAbility"
      :model="specialtyAbility"
      label-position="left"
      label-width="150px"
      :rules="rules"
    >
      <el-form-item label="技能名称" required prop="specialtyName">
        <span slot="label" class="left-label">
          <span calss="cn-label">技能名称</span><br />
          <span class="en-label">Skill Name</span>
        </span>
        <el-input
          v-model="specialtyAbility.specialtyName"
          placeholder="请输入技能名称"
          style="width: 50%"
        />
      </el-form-item>
      <el-form-item label="掌握程度" required prop="level">
        <span slot="label" class="left-label">
          <span calss="cn-label">掌握程度</span><br />
          <span class="en-label">Level</span>
        </span>
        <el-radio
          v-model="specialtyAbility.level"
          :label="item"
          v-for="item in ['一般', '良好', '熟练', '精通']"
        >
          {{ item }}</el-radio
        >
      </el-form-item>
      <el-form-item label=" ">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="submitForm('specialtyAbility')"
          >确定</el-button
        >
        <el-popconfirm
          title="确定删除吗？"
          class="delete-icon"
          @confirm="deleteConfirm"
          v-if="showDel"
        >
          <i class="delete-icon" slot="reference"></i>
        </el-popconfirm>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  components: {},
  props: {},
  data() {
    return {
      specialtyAbility: {
        specialtyName: "", //技能名称
        level: "", //掌握程度
      },
      rules: {
        specialtyName: [
          { required: true, message: "请输入技能名称", trigger: "blur" },
        ],
        level: [
          { required: true, message: "请选择掌握程度", trigger: "change" },
        ],
      },
      index: null,
      showDel: false,
    };
  },
  methods: {
    businessAreaChange(e) {
      console.log(e);
    },
    handleCityChange(e) {
      console.log(e);
    },
    cancel() {
      this.specialtyAbility = {
        specialtyName: "", //技能名称
        level: "", //掌握程度
      };
      this.showDel = false;
      this.index = null;
      this.$parent.$parent.$parent.closeFun("specialtyAbility");
      this.$nextTick(() => {
        this.$refs["specialtyAbility"].clearValidate();
      });
    },
    deleteConfirm() {
      this.$parent.$parent.$parent.deleteFun("specialtyAbility", this.index);
      this.cancel();
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let data = JSON.parse(JSON.stringify(this.specialtyAbility));
          this.$parent.$parent.$parent.upDate(
            "specialtyAbility",
            data,
            this.index
          );
          this.cancel();
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    init(data, index) {
      data = JSON.parse(JSON.stringify(data));
      this.specialtyAbility = data;
      this.index = index;
      this.showDel = true;
    },
  },
  created() {},
  mounted() {},
};
</script>

<style lang="less" scoped>
.delete-icon {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
  display: inline-block;
  width: 32px;
  height: 32px;
  background: url("../../../assets/images/delete_icon.png") no-repeat center
    center / cover;
}
</style>
